import 'package:flutter/material.dart';

/// 处理点击
/// 1. 创建按钮
/// 2. 使用GestureDetector包裹

class HandingTapApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final String appTitle = 'Handing Tap Demo';
    return MaterialApp(
      title: appTitle,
      theme: ThemeData(primarySwatch: Colors.red),
      home: HandingTapAppPage(title: appTitle),
    );
  }
}

class HandingTapAppPage extends StatefulWidget {
  final String title;

  HandingTapAppPage({Key key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() => HandingTapAppPageState();
}

class HandingTapAppPageState extends State<HandingTapAppPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: MyTapButton(),
      ),
    );
  }
}

class MyTapButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Scaffold.of(context).showSnackBar(SnackBar(content: Text('Tap')));
      },
      child: Container(
        padding: EdgeInsets.all(12.0),
        decoration: BoxDecoration(
          color: Theme.of(context).buttonColor,
          borderRadius: BorderRadius.circular(8.0),
        ),
        child: Text('My Button'),
      ),
    );
  }
}
